﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

public partial class BalanceCenter_AdminInformation : PageBase
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!this.IsPostBack)
        {
            BindData();
        }
    }

    #region Web 窗体设计器生成的代码

    protected override void OnLoad(EventArgs e)
    {
        isRequestLogin = true;                                  //是否需要登录
        RequestLoginPage = this.Request.Url.AbsoluteUri;        //获取决对Url
        isAtFramePageLogin = true;                              //是框架页
        RequestCompetences = Competences.BuildCompetencesList(Competences.EditNews);//页面权限

        base.OnLoad(e);
    }

    #endregion

    private void BindData()
    {
        DataTable dt = new DAL.Tables.tbl_Information().Open("", "Type = " + Shove._Convert.StrToInt(ddlType.SelectedValue,-1).ToString(), "[DateTime] desc");

        if (dt == null)
        {
            PublicFunction.GoError(ErrorNumber.DataReadWrite, "数据读写错误", this.GetType().BaseType.FullName);

            return;
        }

        g.DataSource = dt;
        g.DataBind();
        gPager.Visible = (dt.Rows.Count > 0);
    }

    protected void g_ItemDataBound(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.EditItem)
        {
            CheckBox cb = (CheckBox)e.Item.Cells[2].FindControl("cbisShow");
            cb.Checked = Shove._Convert.StrToBool(e.Item.Cells[5].Text, true);

            LinkButton lbdel = (LinkButton)e.Item.Cells[2].FindControl("btnDel");
            lbdel.Attributes.Add("onclick", "return confirm('" + System.Web.HttpUtility.HtmlEncode("您确信要删除此条新闻资料吗？") + "');");
        }
    }

    protected void g_ItemCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
    {
        if (e.CommandName == "Edit")
        {
            this.Response.Redirect("AdminInformationEdit.aspx?id=" + e.Item.Cells[4].Text, true);
            return;
        }
        if (e.CommandName == "Del")
        {
            DAL.Tables.tbl_Information Information = new DAL.Tables.tbl_Information();

            if (Information.Delete("[ID] = " + Shove._Convert.StrToLong(e.Item.Cells[4].Text,-1).ToString()) < 0)
            {
                Shove._Web.JavaScript.Alert(this.Page, "数据删除错误");

                return;
            }

            BindData();

            return;
        }
    }

    protected void btnAdd_Click(object sender, System.EventArgs e)
    {
        this.Response.Redirect("AdminInformationAdd.aspx" + (Shove._Convert.StrToInt(ddlType.SelectedValue, -1) == -1 ? "" : "?ID=" + ddlType.SelectedValue), true);
    }

    protected void gPager_PageWillChange(object Sender, Shove.Web.UI.PageChangeEventArgs e)
    {
        BindData();
    }

    protected void gPager_SortBefore(object source, System.Web.UI.WebControls.DataGridSortCommandEventArgs e)
    {
        BindData();
    }

    protected void ddlType_SelectedIndexChanged(object sender, EventArgs e)
    {
        BindData();
    }
}